<template>
  <el-row :gutter="20" class="mb-5">
    <template v-if="panelList.length === 0">
      <el-col :span="6" v-for="i in 4" :key="i">
        <el-skeleton style="width: 100%" animated loading>
          <template #template>
            <el-card shadow="hover" class="border-0">
              <template #header>
                <div class="flex justify-between">
                  <el-skeleton-item variant="text" style="width: 50%" />
                  <el-skeleton-item variant="text" style="width: 10%" />
                </div>
              </template>
              <el-skeleton-item variant="h3" style="width: 80%" />
            </el-card>
          </template>
        </el-skeleton>
      </el-col>
    </template>
    <template v-else>
      <el-col :span="6" :offset="0" v-for="(item, index) in panelList" :key="item.color">
        <el-card shadow="never">
          <div class="flex items-center">
            <el-icon :size="20" :class="`text-white w-[40px] h-[40px] rounded-full ${item.color}`">
              <User v-if="index === 0" />
              <ShoppingCart v-if="index === 1" />
              <PriceTag v-if="index === 2" />
              <Timer v-if="index === 3" />
            </el-icon>
            <div class="ml-2">
              <h2 class="text-lg font-bold">{{ item.value }}</h2>
              <small class="text-xs text-gray-400">{{ item.label }}</small>
            </div>
          </div>
        </el-card>
      </el-col>
    </template>
  </el-row>
</template>


<script setup>
import { ref, onMounted } from 'vue';
import {
  getDistributionCount
} from '@/api/distribution';

const panelList = ref([]);

const initLoadCount = async () => {
  const { panels } = await getDistributionCount();
  panelList.value = panels;
}


onMounted(() => initLoadCount());
</script>


<style lang="less" scoped>
.bg-blue-400 {
  @apply bg-blue-400;
}

.bg-orange-400 {
  @apply bg-orange-400;
}

.bg-green-400 {
  @apply bg-green-400;
}

.bg-indigo-400 {
  @apply bg-indigo-400;
}
</style>